package com.atguigu.cloud.aop.advice;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @author： yeswater
 * @create： 2024/5/27
 */

@Component
@Aspect
@Slf4j
public class TimeAdvice {
	
	@Around("com.atguigu.cloud.aop.pointcut.MyPointcut.pointcut()")
	public void around(ProceedingJoinPoint joinPoint) {
		long start = System.currentTimeMillis();
		log.info("AOP 方法执行开始 == " + start);
		try {
			joinPoint.proceed();
		} catch (Throwable e) {
			throw new RuntimeException(e);
		} finally {
			long end = System.currentTimeMillis();
			log.info("AOP 方法执行结束 == " + end);
			log.info("AOP 方法执行时间 == " + (end - start) + "ms");
		}
	}
	
}
